﻿@model SimpleTaskManager.Domain.Entities.Task

@using SimpleTaskManager.WebUI.HtmlHelpers;

    <table class="tablesorter" id="taskTable">
<thead>
        <tr>
            <th>Name</th>
            <th>Requires</th>
            <th>Status</th>
            <th>Progress</th>
            <th>Deadline</th>
            <th>Rating</th>
            @if(ViewBag.IsLeader){<th>Action</th>}
        </tr>
</thead>
<tbody>
        @foreach (var t in Model.SubTasks)
        {
            <tr>
                <td>@Html.ActionLink(t.Name, "Details", new { id = t.TaskID })</td>
                <td>@{
                    bool isFirst = true;
                    foreach (var reqTask in t.Requirements)
                    {
                        if (isFirst)
                        {
                            isFirst = !isFirst;
                        }
                        else
                        {
                            <span>, </span>
                        }
                        @Html.ActionLink(reqTask.Name, "Details", new { id = reqTask.TaskID });
                    }
                }</td>
                <td>@t.Status</td>
                <td>@t.Progress.ToPercentage()</td>
                <td>@t.EndDate.ToString("yyyy-MM-dd")</td>
                <td>@t.Rating</td>
                @if(ViewBag.IsLeader){<td>
                        <a href="#" class="AddReqLink ButtonLink" taskid=@t.TaskID>Requirements</a> |
                        @Html.ActionLink("Edit", "Edit", new { id = t.TaskID}) | 
                        @Html.ActionLink("Delete", "Delete", new { id = t.TaskID })</td>}
            </tr>
        }
</tbody>
    </table>